package com.ruitu.ssmic.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ruitu.arad.base.BaseFragment;
import com.ruitu.arad.util.RegexUtils;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.arad.view.EditTextCleanView;
import com.ruitu.ssmic.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class PhoneFragemnt extends BaseFragment {
    private CallBack callBack;
    private TextView tv_next;
    private EditTextCleanView clean_edittext_phone;


    public static PhoneFragemnt newInstance() {
        Bundle args = new Bundle();
        PhoneFragemnt fragment = new PhoneFragemnt();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_phone, null);
        tv_next = view.findViewById(R.id.tv_next);
        clean_edittext_phone = view.findViewById(R.id.clean_edittext_phone);
        tv_next.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (tv_next == v){
            String phone = clean_edittext_phone.getText().toString();
            if (RegexUtils.isMobileSimple(phone)){
                callBack.setCallBack(phone);
            }else
                ToastUtils.showShort("请输入正确的手机号");
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        callBack = (CallBack) getActivity();
    }

    public interface CallBack {
        void setCallBack(String value);
    }
}
